<template>
    <div>
        <el-row type="flex" class="row-bg" justify="space-between">
            <div>
                <span @click="goBack" class="p_cals">{{$t('requirement.registration')}}</span> /
                <span>{{$t('requirement.audit')}}</span>
            </div>
            <el-button @click="cancelDialog" type="text">{{$t('requirement.back')}}</el-button>
        </el-row>
        <div v-if=" details==='详情' ">

        </div>
        <div style="padding:0 20px;" v-else>
            <el-card
                shadow="never"
                v-loading="loading"
                body-style="padding: 24px;"
                class="card-margin"
            >
                <div style="display: flex;justify-content: space-between;">
                    <p class="base-info-title">基本信息</p>
                </div>
                <table class="table-style-baseinfo">
                    <tr>
                        <td class="text-right-background-color">{{$t('internship.internshipBase')}}:</td>
                        <td class="text-left-background-none">{{dataForm.baseName}}</td>
                        <td class="text-right-background-color">岗位名称:</td>
                        <td class="text-left-background-none">{{dataForm.positionName}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">{{$t('graduate.college')}}:</td>
                        <td
                            class="text-left-background-none"
                        >{{dataForm.collegeAcademy | collegeAcademyList(options.faculty)}}</td>
                        <td class="text-right-background-color">专业:</td>
                        <td
                            class="text-left-background-none"
                        >{{dataForm.major | collegeAcademy(options.title)}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">岗位需求人数:</td>
                        <td class="text-left-background-none">{{dataForm.personNum}}</td>
                        <td class="text-right-background-color">工作地点:</td>
                        <td class="text-left-background-none">{{dataForm.workAddress}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">待遇:</td>
                        <td class="text-left-background-none" colspan="3">{{dataForm.treatment}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">工作日期起:</td>
                        <td class="text-left-background-none">{{dataForm.workTimeStart}}</td>
                        <td class="text-right-background-color">工作日期止:</td>
                        <td class="text-left-background-none">{{dataForm.workTimeEnd}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">专业要求:</td>
                        <td
                            class="text-left-background-none"
                            colspan="3"
                        >{{dataForm.majorRequirements}}</td>
                    </tr>
                    <tr>
                        <td class="text-right-background-color">申报时间起:</td>
                        <td class="text-left-background-none">{{dataForm.applyTimeStart}}</td>
                        <td class="text-right-background-color">申报时间止:</td>
                        <td class="text-left-background-none">{{dataForm.applyTimeEnd}}</td>
                    </tr>
                    <tr>
                        <td class="text-right-background-color">{{$t('internship.adjunct')}}:</td>
                        <td
                            class="text-left-background-none"
                            colspan="3"
                            style="max-width: 300px; word-wrap: break-word; overflow: auto;"
                        >
                            <a
                                @click="fileName(dataForm.enclosureFileUrl)"
                            >{{dataForm.enclosureFileName}}</a>
                        </td>
                    </tr>
                </table>
            </el-card>

            <el-card
                shadow="never"
                v-loading="loading"
                body-style="padding: 24px;"
                class="card-margin"
            >
                <div style="display: flex;justify-content: space-between;">
                    <!-- <p class="base-info-title">{{$t('internship.reviewDetail')}}</p> -->
                    <p class="base-info-title">学生信息</p>
                </div>
                <table class="table-style-baseinfo">
                    <tr>
                        <td class="text-right-background-color">姓名:</td>
                        <td class="text-left-background-none">{{dataFormList.studentName}}</td>
                        <td class="text-right-background-color">学号:</td>
                        <td class="text-left-background-none">{{detailInfo.studentId}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">{{$t('graduate.college')}}:</td>
                        <td
                            class="text-left-background-none"
                        >{{dataFormList.faculty | collegeAcademyList(options.faculty)}}</td>
                        <td class="text-right-background-color">专业:</td>
                        <td
                            class="text-left-background-none"
                        >{{dataFormList.profession | collegeAcademy(options.title)}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">培养层次:</td>
                        <td
                            class="text-left-background-none"
                        >{{dataFormList.trainingLevel|collegeAcademyList(options.TrainingLevel)}}</td>
                        <td class="text-right-background-color">培养类别:</td>
                        <td
                            class="text-left-background-none"
                        >{{dataFormList.trainingCategory|collegeAcademyList(options.trainingCategory)}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">学位类型:</td>
                         <td
                            class="text-left-background-none"
                        >{{dataFormList.degreeType|collegeAcademyList(options.degreeType)}}</td>
                        <td class="text-right-background-color">学习形式:</td>
                        <td
                            class="text-left-background-none"
                        >{{dataFormList.formLearning|collegeAcademyList(options.formLearning)}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">年级:</td>
                        <td class="text-left-background-none">{{dataFormList.grade}}</td>
                        <td class="text-right-background-color">导师:</td>
                        <td class="text-left-background-none">{{dataFormList.teacher}}</td>
                    </tr>

                    <tr>
                        <td class="text-right-background-color">个人特长:</td>
                        <td
                            colspan="3"
                            style="max-width: 300px; word-wrap: break-word; overflow: auto;"
                            class="text-left-background-none"
                        >{{detailInfo.specialSkill}}</td>
                    </tr>
                    <tr>
                        <td class="text-right-background-color">取得成果:</td>
                        <td
                            colspan="3"
                            style="max-width: 300px; word-wrap: break-word; overflow: auto;"
                            class="text-left-background-none"
                        >{{detailInfo.achievements}}</td>
                    </tr>
                </table>
            </el-card>

            <el-card
                shadow="never"
                v-loading="loading"
                body-style="padding: 24px;"
                class="card-margin"
            >
                <h1 class="condition-title">{{$t('internship.audit')}}</h1>
                <div>
                    <el-form
                        :model="internship"
                        ref="internship"
                        label-width="80px"
                        label-position="left"
                        style="margin:24px 0 0 12px;"
                        :rules="internshipRule"
                    >
                        <el-form-item :label="$t('internship.auditOpinion')">
                            <el-input
                                maxlength="500"
                                v-model="internship.opinion"
                                type="textarea"
                                :rows="7"
                                :placeholder="$t('identificationToDoList.placeholder1')"
                            ></el-input>
                        </el-form-item>
                    </el-form>
                </div>
                <div style="text-align: right;">
                    <span>
                        <el-button @click="goBack">{{$t('graduate.cancel')}}</el-button>
                        <el-button
                            type="danger"
                            @click="reject"
                        >{{$t('identificationToDoList.Reject')}}</el-button>
                        <el-button
                            type="primary"
                            @click="pass"
                        >{{$t('identificationToDoList.adopt')}}</el-button>
                    </span>
                </div>
            </el-card>
            <HistoryTable :tableData="tableData" :nodes='true'></HistoryTable>
        </div>
    </div>
</template>
<script>
import { downloadfile } from 'common/src/api/upload'
import HistoryTable from 'common/src/views/graduateStudent/component/HistoryTable'
import { queryDic } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
import graduateStudent from 'common/src/api/graduateStudent/graduateStudent'
export default {
    components: {
        HistoryTable
    },
    data() {
        return {
            dataFormList: {},
            queryForm: {}, //接收路由跳转的数据
            dataForm: {
                opinion: '',
                fileList: [],
                achievementId: '',
                studentId: '',
                practiceId: '',
                calendarId: ''
            }, //表格数据
            internship: {
                opinion: ''
            },
            dataInfo: {},
            detailInfo: {},
            curCheckStandard: '',
            curPracticeId: '',
            options: {
                faculty: [],
                degreeType: [],
                title: [],
                sex: [],
                trainingCategory: [],
                profession: [],
                TrainingLevel: [],
                formLearning: []
            },
            internshipRule: {
                opinion: [
                    {
                        required: true,
                        message: this.$t('myExamine.reviewComments'),
                        trigger: 'blur'
                    }
                ]
            },
            tableData: []
        }
    },
    filters: {
        collegeAcademyList(val, array) {
            let str = ''
            for (let item of array) {
                if (val === item.value) {
                    str = item.label
                }
            }
            return str
        },
        collegeAcademy(val, array) {
            let list = []
            let str = []
            if (val) {
                list = val.split(',')
                list.forEach(el => {
                    array.forEach(ele => {
                        if (el == ele.value) {
                            str.push(ele.label)
                        }
                    })
                })
                return str.join()
            }
        }
    },
    watch: {
        showFlag: {
            handler: function(newV, oldV) {
                if (newV) {
                    this.dataForm = this.$route.query.data
                    this.tableData = this.$route.query.list
                }
            }
        }
    },
    mounted() {
        this.getOptions()
        this.getQueryPractice()
    },
    created() {
        this.detailInfo = this.$route.query.dataInfo
        graduateStudent.getregDetailAudit(this.detailInfo.actNo).then(res => {
            if (res.code === 200) {
                this.tableData = res.data
            }
        })

        graduateStudent
            .getSession()
            .then(res => {
                this.id = res.data.realUid
                this.name = res.data.session.mockName
            })
            .then(() => {
                this.getStuDetailBy()
            })
    },
    methods: {
        fileName(path) {
            downloadfile(path)
        },
        getQueryPractice() {
            graduateStudent.regGetDetail(this.$route.query.dataInfo.needsId).then(resd => {
                this.dataForm = resd.data
            })
        },
        getOptions() {
            // 筛选条件字典查询
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['X_YX', 'G_XBIE', 'X_XWLX', 'G_ZY','X_XXXS','X_PYCC','X_PYLB']
            }
            queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        faculty: 'X_YX',
                        degreeType: 'X_XWLX',
                        sex: 'G_XBIE',
                        title: 'G_ZY',
                        trainingCategory: 'X_PYLB',
                        TrainingLevel: 'X_PYCC',
                        formLearning: 'X_XXXS'
                    },
                    res.data,
                    this.options
                )
            })
        },
        // 学生信息
        getStuDetailBy() {
            let obj = {
                id: this.$route.query.dataInfo.studentId
            }
            graduateStudent.getStuDetailByClass(obj).then(res => {
                this.dataFormList = res.data[0]
            })
        },
        // 驳回
        reject() {
            if (this.internship.opinion.indexOf('$') < 0) {
                if (this.internship.opinion) {
                    let practiceIds = []
                    practiceIds.push({
                        no: this.$route.query.dataInfo.actNo,
                        content: this.internship.opinion
                    })
                    graduateStudent.internshipRefuse(practiceIds).then(data => {
                        this.$message({
                            type: 'success',
                            message: this.$t('identificationToDoList.SuccessfulOperation')
                        })
                        this.goBack()
                    })
                } else {
                    this.$message({
                        type: 'error',
                        message: this.$t('myExamine.reviewComments')
                    })
                }
            } else {
                this.$message({
                    type: 'error',
                    message: this.$t('identificationToDoList.cannotContain')
                })
            }
        },
        // 通过
        pass() {
            if (this.internship.opinion.indexOf('$') < 0) {
                let practiceIds = []
                practiceIds.push({
                    no: this.$route.query.dataInfo.actNo,
                    content: this.internship.opinion
                })
                graduateStudent.internshipAgree(practiceIds).then(data => {
                    this.$message({
                        type: 'success',
                        message: this.$t('identificationToDoList.SuccessfulOperation')
                    })
                    this.goBack()
                })
            } else {
                this.$message({
                    type: 'error',
                    message: this.$t('identificationToDoList.cannotContain')
                })
            }
        },
        // 返回
        goBack() {
            this.$store.commit('delete_tabs', this.$route.path)
            this.$router.go(-1)
        },
        cancelDialog() {
            this.$store.commit('delete_tabs', this.$route.path)
            this.$router.go(-1)
        }
    }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.p_cals:hover {
    cursor: pointer;
    color: #409eff;
}
.p_cals {
    color: #aaa;
}
.inner-breadcrumb {
    .breadcrumb {
        span {
            font-weight: normal;
            color: #aaa;
        }
        a {
            font-weight: normal;
            color: #aaa;
        }
        a:hover {
            color: #409eff;
        }
        .last {
            font-weight: bold !important;
            cursor: default !important;
        }
        .disable {
            cursor: default !important;
        }
    }
}
.condition-title-p {
    font-weight: 400;
    font-style: normal;
    color: #2b3b4e;
    font-size: 18px;
    margin-bottom: 15px;
}
.base-info-title {
    font-weight: 400;
    font-style: normal;
    font-size: 16px;
    color: #2b3b4e;
}
.table-style-baseinfo {
    background-color: rgba(210, 212, 214, 1);
    box-sizing: border-box;
    border-width: 0.5px;
    border-style: solid;
    border-color: rgba(210, 212, 214, 1);
    border-radius: 0px;
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
    width: 100%;
    font-weight: 401;
    font-style: normal;
    font-size: 14px;
    color: #8896a7;
    margin-bottom: 20px;
}
.table-style-baseinfo td {
    width: 25%;
    background-color: rgba(255, 255, 255, 1);
    border: none;
    border-radius: 0px;
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
    font-weight: 401;
    font-style: normal;
    font-size: 14px;
    color: #2b3b4e;
    height: 32px;
    padding: 0 10px;
}
.table-style-baseinfo .text-right-background-color {
    background-color: #fdfeff4d;
    text-align: right;
}
.text-left-background-none {
    text-align: left;
}
</style>
